using System;
using Resources;

namespace ScrewTurn.Wiki
{
    public partial class Upload : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = Messages.UploadTitle + " - " + Settings.WikiTitle;

            lblDescription.Text = lblDescription.Text.Replace("##MAXFILESIZE##",
                                                              Tools.BytesToString(Settings.MaxFileSize*1024));

            if (SessionFacade.LoginKey != null)
            {
                // Registered User
                if (!SessionFacade.Admin)
                {
                    // Normal User
                    if (!Settings.UsersCanViewFiles) Response.Redirect("AccessDenied.aspx");
                }
                // Else: User is an Admin, therefore can do any operation
            }
            else
            {
                // Anonymous User
                if (!Settings.PublicAccess) Response.Redirect("Login.aspx?Redirect=Upload.aspx");
                else
                {
                    // Public Access
                    if (!Settings.UsersCanViewFiles) Response.Redirect("Login.aspx?Redirect=Upload.aspx");
                    else
                    {
                        if (!Settings.FileManagementInPublicAccessAllowed)
                            Response.Redirect("Login.aspx?Redirect=Upload.aspx");
                    }
                }
            }
        }
    }
}